package com.example.dianproject.repository;

import com.example.dianproject.entity.ElectricityPrice;
import com.example.dianproject.entity.ElectricityPrice.CustomerType;
import org.springframework.data.jpa.repository.JpaRepository;
import org.springframework.data.jpa.repository.Query;
import org.springframework.data.repository.query.Param;
import org.springframework.stereotype.Repository;

import java.util.List;
import java.util.Optional;

@Repository
public interface ElectricityPriceRepository extends JpaRepository<ElectricityPrice, Integer> {
    
    @Query(value = "SELECT * FROM electricity_price WHERE customer_type = :type ORDER BY effective_date DESC, id DESC LIMIT 1", nativeQuery = true)
    Optional<ElectricityPrice> findCurrentPriceByType(@Param("type") String type);
    
    @Query(value = "SELECT * FROM electricity_price ORDER BY effective_date DESC, id DESC", nativeQuery = true)
    List<ElectricityPrice> findAllOrderByEffectiveDateDesc();
} 